package cn.tedu.hospital.admin.server.freebased.controller;

import cn.tedu.hospital.admin.server.common.pojo.vo.PageData;
import cn.tedu.hospital.admin.server.common.web.JsonResult;
import cn.tedu.hospital.admin.server.freebased.pojo.param.FreeBasedAddNewParam;
import cn.tedu.hospital.admin.server.freebased.pojo.vo.FreeBasedListItemVO;
import cn.tedu.hospital.admin.server.freebased.pojo.vo.FreeBasedStandardVO;
import cn.tedu.hospital.admin.server.freebased.service.IFreeBasedService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 处理消费信息相关请求的控制器类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/freebased")
@Api(tags = "8.1. 消费信息管理-基本信息管理")
public class FreeBasedController {

    @Autowired
    private IFreeBasedService freeBasedService;

    public FreeBasedController() {
        log.debug("创建控制器类对象：ArticleController");
    }

    @PostMapping("/add-new")
   // @PreAuthorize("hasAuthority('/content/article/add-new')")
    @ApiOperation("添加消费信息")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid FreeBasedAddNewParam freeBasedAddNewParam) {
        log.debug("开始处理【发布消费信息】的请求，参数：{}", freeBasedAddNewParam);
      //  String remoteAddr = request.getRemoteAddr();
        freeBasedService.addNew(freeBasedAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
   // @PreAuthorize("hasAuthority('/content/article/delete')")
    @ApiOperation("根据ID删除消费信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "消费信息ID", required = true, dataType = "long")
    })
    public JsonResult delete(@PathVariable @Range(min = 1, message = "请提交有效的患者ID值！") Long id) {
        log.debug("开始处理【根据ID删除消费信息】的请求，参数：{}", id);
        freeBasedService.delete(id);
        return JsonResult.ok();
    }


    @GetMapping("/{id:[0-9]+}")
    //@PreAuthorize("hasAuthority('/content/article/read')")
    @ApiOperation("根据ID查询消费信息详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "患者ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(
            @PathVariable @Range(min = 1, message = "请提交有效的患者ID值！") Long id) {
        log.debug("开始处理【根据ID查询消费信息详情】的请求，参数：{}", id);
        FreeBasedStandardVO queryResult = freeBasedService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @GetMapping("/list")
   // @PreAuthorize("hasAuthority('/content/article/read')")
    @ApiOperation("查询消费信息列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "long"),
    })
    public JsonResult list(@Range(min = 1, message = "请提交有效的页码值！") Integer page) {
        log.debug("开始处理【查询消费信息列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<FreeBasedListItemVO> pageData = freeBasedService.list(pageNum);
        return JsonResult.ok(pageData);
    }


}
